package org.mtmi.ui.drawables;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

public class ImageDrawable implements IDrawable 
{
	private Image image;
	
	/** caller is responsible to dispose image */
	public ImageDrawable( Image img ) {
		image = img;
	}
	
	public Image getImage() { return image; }
	
	public void setImage( Image img ) { image = img; }
	
	@Override
	public Point computeSize( int width, int height ) {
		//pixel image is fixed size
		Rectangle ri = image.getBounds();
		return new Point( ri.width, ri.height );
	}

	@Override
	public void paint( GC gc, int x, int y, int width, int height, int state ) {
		
		if( state == DISABLED ) {
			int a = gc.getAlpha();
			gc.setAlpha( 100 );
			gc.drawImage( image, x, y );
			gc.setAlpha( a );
		} else {
			gc.drawImage( image, x, y );
		}
	}

}
